import urllib.request

# 方法1
response = urllib.request.urlopen('http://www.baidu.com')
print(response.read().decode('utf-8'))  # 获得响应体,返回byte类型,需要转码

# 方法2-Request
request = urllib.request.Request('http://www.baidu.com')
response1 = urllib.request.urlopen(request)
print(response1.read().decode('utf-8'))


